package com.ruoyi.web.threadLocal;

import com.ruoyi.web.context.RequestContext;
import com.ruoyi.web.context.RequestContextHolder;

public abstract class ThreadCache {

    /**
     * 请求上下文
     */
    private static final ThreadLocal<RequestContext> REQUEST_CONTEXT = ThreadLocal.withInitial(() -> null);


    public static RequestContext getRequestContext() {
        return REQUEST_CONTEXT.get();
    }

    public static void initRequestContext() {
        RequestContext requestContext = RequestContextHolder.initRequestContext();
        REQUEST_CONTEXT.set(requestContext);
    }

    public static void removeRequestContext() {
        REQUEST_CONTEXT.remove();
    }


    public static void removeAll() {
        removeRequestContext();
    }

}
